/*
 * @Author: underMoonzs 1994186472@qq.com
 * @Date: 2025-09-03 20:19:17
 * @LastEditors: underMoonzs 1994186472@qq.com
 * @LastEditTime: 2025-10-04 11:31:19
 * @FilePath: \lyshjpt\src\views\biz\api\pollution.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import request from "@/utils/request";

// 格式化日期为 YYYY-MM-DD
const formatDate = (date) => {
  const year = date.getFullYear();
  const month = String(date.getMonth() + 1).padStart(2, "0");
  const day = String(date.getDate()).padStart(2, "0");
  return `${year}-${month}-${day}`;
};

// 预警点数据
export function getYujing(query) {
  // 如果query为空或者没有beginTime和endTime，则设置默认值
  const params = query || {};
  if (!params.beginTime && !params.endTime) {
    const today = new Date();
    const yesterday = new Date(today);
    yesterday.setDate(yesterday.getDate() - 1);

    params.beginTime = formatDate(yesterday);
    params.endTime = formatDate(today);
  }

  return request({
    url: "/gis/warning/warnPointData",
    method: "get",
    params: params,
  });
}


// 预警点详情
export function getYujingDetail(query) {
  return request({
    url: "/gis/warning/warnDetail",
    method: "get",
    params: query,
  });
}
